//
//  CZD_GoodBillListVC.m
//  LogisticsSupplier
//
//  Created by 吕晶 on 2020/9/28.
//  Copyright © 2020 吕晶. All rights reserved.
//

#import "CZD_GoodBillListVC.h"
#import "CZD_GoodBillListCell.h"
#import "TiDanGoodListVC.h"

@interface CZD_GoodBillListVC ()<UITableViewDelegate,UITableViewDataSource>

@property (nonatomic, strong) NSArray *dataArray;
@property (nonatomic, strong) UITableView *tableView;

@end

@implementation CZD_GoodBillListVC

-(UITableView *)tableView {
    if (!_tableView) {
        _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, ScreenW, ScreenH - NaviHeight - BottomHeight) style:UITableViewStyleGrouped];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.backgroundColor = Color_backgroundColor;
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    }
    return _tableView;
}

-(NSArray *)dataArray {
    if (!_dataArray) {
        _dataArray = [NSArray array];
    }
    return _dataArray;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"货物清单";
    [self.view addSubview:self.tableView];
    [self requestForData];
}

- (void)requestForData {
    [HttpRequest PostWithApi:LogisticsSupplierCaoZuoDanYunDanGoodBillList params:@{@"wa_id":self.wa_id} progress:^(NSProgress * _Nonnull progress) {
        
    } success:^(NSURLSessionDataTask * _Nonnull operation, id  _Nonnull responseObject, BOOL code, NSInteger errorCode) {
        if (code) {
            self.dataArray = responseObject;
            [self.tableView reloadData];
        }
    } fail:^(NSError * _Nonnull error) {
        
    }];
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.dataArray.count;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    CZD_GoodBillListCell *cell = [CZD_GoodBillListCell CZD_GoodBillListCellWithTableView:tableView];
    NSDictionary *dic = self.dataArray[indexPath.row];
    cell.num = dic[@"serial_num"];
    return cell;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    CZD_GoodBillListCell *cell = [CZD_GoodBillListCell CZD_GoodBillListCellWithTableView:tableView];
    return cell.height;
}

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    return [UIView new];
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return 0;
}

-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenW, 10)];
    view.backgroundColor = Color_backgroundColor;
    return view;
}

-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    return 10;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    NSDictionary *dic = self.dataArray[indexPath.row];
    TiDanGoodListVC *vc = [TiDanGoodListVC new];
    vc.dp_id = dic[@"dp_id"];
    [self.rt_navigationController pushViewController:vc animated:YES];
}

@end
